||(OR) Operator

The OR operator is somewhat opposite of the ‘AND’ operator. It also evaluates the operator from left to right and returns true even if one operand is evaluated as true

Example: In this example, we will perform OR operation on different data types and check their boolean output.

Javascript
// ||(OR) Operator
let i = 1;
let j = null;
let k = undefined;
let l = 0;
console.log(Boolean(j||k));
console.log(Boolean(i||l));

Output:

false
true

Explanation: null, undefined, and 0 are recognized as falsy values. So OR operation on null and undefined will give false whereas numbers except 0 are treated as true.

Supported Browsers: The browsers supported by all JavaScript Logical operators are listed below:

We have a complete list of Javascript Operators, to check those please go through this Javascript Operators Complete reference article.

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.



JavaScript Logical Operators

Similar Reads

Logical operators

The logical operators are mostly used to make decisions based on conditions specified for the statements. It can also be used to manipulate a boolean or set termination conditions for loops. It allows us to compare variables or values....

!(NOT) Operator

!(NOT) Operator reverses the boolean result of the operand (or condition). It first converts the operand to a boolean type and then returns its flipped value....

&&(AND) Operator

The && operator accepts multiple arguments and evaluates the operator from left to right. It returns true only if all the operands that are evaluated are true...

||(OR) Operator

The OR operator is somewhat opposite of the ‘AND’ operator. It also evaluates the operator from left to right and returns true even if one operand is evaluated as true...

Contact Us